/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rc;

import tal.drivechain.matchers.VarMatcher;
import tal.drivechain.plugin.Channel;
import tal.drivechain.variable.Variable;
import tal.drivechain.variable.types.DataType;
import tal.remotecanvas.UIComponent;
import tal.remotecanvas.UISlider;

/**
 *
 * @author Tal Eisenberg
 */
public class Slider extends UI {
    VarMatcher trigger = new VarMatcher();

    public Slider() {
        component = new UISlider();
    }

    public void valueChanged(UIComponent source, Object value) {
        if (debugFlag) log("Value changed: " + value, MSG.DEBUG);
    }

    public void setTrigger(VarMatcher t) { this.trigger = t; }
    public VarMatcher getTrigger() { return this.trigger; }

    public void setMomentary(Boolean m) {
        ((UISlider)component).setMomentary(m);
    } public boolean getMomentary() { return ((UISlider)component).isMomentary(); }

    @Override
    protected void msgReceived(Variable in, long timestamp, Channel channel) {
        if (trigger.matches(in, channel, this)) {
            double newVal = (Double)DataType.FLOAT.cast(in.getValue(this));
            ((UISlider)component).setValue(newVal);
        } else super.msgReceived(in, timestamp, channel);
    }
}
